package com.wind.taobao.api.trade.item.convert
{
	import com.wind.taobao.api.trade.item.model.PropImg;
	import com.wind.taobao.core.util.TaobaoConstants;
	
	import mx.collections.ArrayCollection;


	/**
	 * PropImg转换器
	 * @author fxy
	 */
	public class PropImgConvert
	{
		/**
		 * 转换PropImg集合
		 */
		public static function convertPropImgs(value:Object, type:String="json"):ArrayCollection
		{
			var propImgs:ArrayCollection=new ArrayCollection();
			if (value != null)
			{
				if (type == TaobaoConstants.JSON)
				{
					if ((value as Array).length > 0)
					{
						for (var i:uint=0; i < (value as Array).length; i++)
						{
							propImgs.addItem(convertPropImg((value as Array)[i]));
						}
					}
				}
				else
				{
					//TODO
				}
			}
			return propImgs;
		}

		/**
		 * 转换PropImg
		 */
		public static function convertPropImg(value:Object, type:String="json"):PropImg
		{
			var propImg:PropImg=new PropImg();
			if (value == null)
				return propImg;
			if (type == TaobaoConstants.XML)
			{
				propImg=convertXMLToPropImg(XML(value), propImg);
			}
			else
			{
				propImg=convertJSONToPropImg(value, propImg);
			}
			return propImg;
		}

		/**
		 * JSON转换为PropImg
		 */
		private static function convertJSONToPropImg(json:Object, propImg:PropImg):PropImg
		{
			if (json.hasOwnProperty(TaobaoConstants.PROPIMG_ID))
			{
				propImg.propimgId=json[TaobaoConstants.PROPIMG_ID];
			}
			if (json.hasOwnProperty(TaobaoConstants.URL))
			{
				propImg.url=json[TaobaoConstants.URL];
			}
			if (json.hasOwnProperty(TaobaoConstants.POSITION))
			{
				propImg.position=json[TaobaoConstants.POSITION];
			}
			if (json.hasOwnProperty(TaobaoConstants.PROPERTIES))
			{
				propImg.properties=json[TaobaoConstants.PROPERTIES];
			}
			return propImg;
		}

		/**
		 * XML转换为PropImg
		 */
		private static function convertXMLToPropImg(value:XML, propImg:PropImg):PropImg
		{
			return propImg;
		}
	}
}